package com.mzj.saas.rent;

import com.haixiaoke.saas.repository.core.AjaxResult;
import com.haixiaoke.saas.repository.core.BaseController;
import com.haixiaoke.saas.repository.core.page.TableDataInfo;
import com.haixiaoke.saas.repository.pojo.HouseQuitLease;
import com.haixiaoke.saas.repository.service.IHouseQuitLeaseService;
import com.haixiaoke.saas.repository.vo.HouseQuitLeaseVo;
import com.mzj.saas.annotation.CheckAuth;
import com.mzj.saas.annotation.RepeatSubmit;
import com.mzj.saas.util.LoginUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;


/**
 * 公寓管理退租记录Controller
 *
 * @author qixi
 * @date 2023-04-18
 */
@RestController
@RequestMapping("/quit/lease")
public class HouseQuitLeaseController extends BaseController {
    @Autowired
    private IHouseQuitLeaseService houseQuitLeaseService;
    @Autowired
    private LoginUserUtil loginUserUtil;

    /**
     * 查询公寓管理退租记录列表
     */
    @GetMapping("/list")
    @CheckAuth
    public TableDataInfo list(HouseQuitLease houseQuitLease) {
        startPage();
        houseQuitLease.setOrgId(loginUserUtil.getOrgId());
        List<HouseQuitLeaseVo> list = houseQuitLeaseService.selectHouseQuitLeaseList(houseQuitLease);
        return getDataTable(list);
    }


    /**
     * 根据订单id 查询公寓管理退租记录列表
     */
    @GetMapping("/listByOrderId/{orderId}")
    @CheckAuth
    public AjaxResult listByOrderId(@PathVariable String orderId) {
        return success(houseQuitLeaseService.selectHouseQuitLeaseVoByOrderId(orderId));
    }



    /**
     * 获取公寓管理退租记录详细信息
     */
    @GetMapping(value = "/{quitLeaseId}")
    @CheckAuth
    public AjaxResult getInfo(@PathVariable("quitLeaseId") Long quitLeaseId) {
        return success(houseQuitLeaseService.selectHouseQuitLeaseByQuitLeaseId(quitLeaseId));
    }


    /**
     * 新增公寓管理退租记录
     */
    @PostMapping
    @CheckAuth
    @RepeatSubmit
    public AjaxResult add(@Valid  @RequestBody HouseQuitLease houseQuitLease) {
        String id = loginUserUtil.getId();
        String name = loginUserUtil.getName();
        String phone = loginUserUtil.getPhone();

        houseQuitLease.setTenantId(id);
        houseQuitLease.setTenantName(name);
        houseQuitLease.setTenantPhone(phone);
        houseQuitLease.setCreateBy(id);
        return toAjax(houseQuitLeaseService.insertHouseQuitLease(houseQuitLease));
    }

    /**
     * 修改公寓管理退租记录
     */
    @PutMapping
    @CheckAuth
    @RepeatSubmit
    public AjaxResult edit(@Valid @RequestBody HouseQuitLease houseQuitLease) {
        String id = loginUserUtil.getId();
        houseQuitLease.setUpdateBy(id);
        return toAjax(houseQuitLeaseService.updateHouseQuitLease(houseQuitLease));
    }

    /**
     * 删除公寓管理退租记录
     */
    @DeleteMapping("/{quitLeaseIds }")
    @CheckAuth
    @RepeatSubmit
    public AjaxResult remove(@PathVariable Long[] quitLeaseIds) {
        return toAjax(houseQuitLeaseService.deleteHouseQuitLeaseByQuitLeaseIds(quitLeaseIds));
    }
}

